<template>
    <el-container class="container">
        <el-aside class="contain_aside">
            <div class="logo">
                <img style="width: 83px;" src="" alt="">
            </div>
            <ul class="menu">
                <li v-for="(item, index) in menu" :key="index" :class="selected == index ? 'active' : ''"
                    @click="go(item.path, index)">
                    <i :class="item.icon"></i>
                    <p>{{ item.name }}</p>
                </li>
            </ul>
        </el-aside>
        <el-main class="main">
            <router-view></router-view>
        </el-main>
    </el-container>
</template>

<script>
export default {
    data: function () {
        return {
            menu: [
                {
                    name: '首页',
                    icon: 'el-icon-s-home',
                    path: '/workContent'
                },
                {
                    name: '系统管理',
                    icon: 'el-icon-s-finance',
                    path: '/memberConsume'
                },
                {
                    name: '用户管理',
                    icon: 'el-icon-s-ticket',
                    path: '/memberDeposit'
                },
                {
                    name: '设备管理',
                    icon: 'el-icon-s-custom',
                    path: '/memberManage'
                },
                {
                    name: '日志管理',
                    icon: 'el-icon-s-order',
                    path: '/financialManage'
                },
                {
                    name: '证书管理',
                    icon: 'el-icon-s-tools',
                    path: '/systemOption'
                },
                {
                    name: '服务管理',
                    icon: 'el-icon-s-tools',
                    path: '/services'
                },
            ],
            selected: 0,
            screenWidth: document.body.clientWidth,
            screenHeight: document.body.clientHeight,
        }
    },
    watch: {
        screenWidth: {
            immediate: true,
            handler: function (newVal) {
                // 为了避免频繁触发resize函数导致页面卡顿，使用定时器
                if (!this.timer) {
                    this.screenWidth = newVal;
                    this.timer = true;
                    let _this = this;
                    setTimeout(() => {
                        //在这里做有关浏览器变化时需要做的操作
                        _this.timer = false;
                    }, 400);
                }
                // if(newVal)
            }
        },
        screenHeight: {
            immediate: true,
            handler: function (newVal) {
                // 为了避免频繁触发resize函数导致页面卡顿，使用定时器
                if (!this.timer) {
                    this.screenHeight = newVal;
                    this.timer = true;
                    let _this = this;
                    setTimeout(() => {
                        //在这里做有关浏览器变化时需要做的操作
                        _this.timer = false;
                    }, 400);
                }
                // if(newVal)
            }
        }
    },
    mounted() {
        // document.querySelector('.container').style.height = document.documentElement.clientHeight + 'px';
        const currentPath = this.$route.path
        const path = currentPath.split('/')[1]
        // 根据当前路径找到index
        this.menu.forEach((item, index) => {
            if (item.path === ('/' + path)) {
                this.selected = index
            }
        })
        window.addEventListener("orientationchange", () => {
            this.screenWidth = document.body.clientWidth;
            this.screenHeight = document.body.clientHeight;
            document.querySelector('.container').style.height = document.body.clientHeight + 'px';
            document.querySelector('.main').style.height = document.body.clientHeight + 'px';
        });
    },
    methods: {
        go(e, index) {
            // if (e !== this.$route.path) {
            this.selected = index
            sessionStorage.removeItem('memberManageSelectedIndex')
            console.log(e)
            this.$router.push(e)
            // }

        }
    }
}
</script>

<style scoped>
.container {
    margin: 0;
    padding: 0;
    height: 100vh;
    width: 100vw;
    display: flex;
    /* background-color: #f0f2f5; */
    background-color: #e6e8eb;
}

.contain_aside {
    width: .875rem !important;
    height: 100%;
}

.logo {
    padding: 40px 0;
    display: flex;
    justify-content: center;
    align-items: center;
}

.logo img {
    width: .75rem;
    height: .75rem;
    border-radius: 50%;
}

.el-aside {
    background-image: linear-gradient(to bottom, #7B63C7, #3BB6FE);
    border-radius: 0 .75rem 0 0;
}
.main{
    flex: 1;
    height: 100%;
}
.el-main {
    padding: 0 !important;
}

.menu li {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: .85rem;
    font-size: .1875rem;
    color: #fff;
    cursor: pointer;
    margin-right: 5px;
}

.menu li.active {
    background: #fff;
    border-radius: 0 8px 8px 0;
    color: #7B63C7;

}

.menu li i {
    font-size: .325rem;
}

.note {
    display: flex;
    align-items: center;
    font-size: .1875rem;
    color: #333;
}

.note i {
    font-size: .225rem;
    color: #ff6600;
    margin-right: .0375rem;
}
</style>
